#!/bin/bash

EXEC=""
TARGET="bin"
declare -A PARAMS
declare -i INDEX=0

for e in $@; do
  TARGET="$TARGET/$e"
  PARAMS[$INDEX]=$e
  INDEX=$INDEX+1
  shift
  if [ -x "${TARGET}.sh" ]; then
    EXEC="${TARGET}.sh"
    PARAMS=()
    INDEX=0
  fi
done

echo ">> $EXEC"
exec "$EXEC" $PARAMS
